import { createStore } from 'vuex'

export default createStore({
  state: {
    uid:null, // 记录登录的用户
    user:null, // 登录用户信息
    cache:{}  // 缓存信息
  },
  mutations: {
    // 设置登录id
    setUid(state,id){
      state.uid = id
    },
    // 设置登录用户
    setUser(state,user){
      state.user = user
    },
    // 设置缓存
    setCache(state,val){
      for(let i in val){
        state.cache[i] = val[i]
      }
    },
    setCacheSidAndName(state,params){
      state.cache.user.sid = params.sid
      state.cache.user.sname = params.sname
    }
  },
  getters: {
    getCache: (state)=>(val)=>{
      return state.cache[val]
    }
  },
  actions: {
  },
  modules: {
  }
})
